package com.congee02;

public class MaxScore_TL {

    public int maxScore(int[] cardPoints, int k) {
        return help(cardPoints, 0, cardPoints.length - 1, k);
    }

    private int help(int[] cardPoints, int st, int ed, int rest) {
        if (rest == 0) {
            return 0;
        }
        if (st == ed) {
            return cardPoints[st];
        }
        int l = cardPoints[st] + help(cardPoints, st + 1, ed, rest - 1);
        int r = cardPoints[ed] + help(cardPoints, st, ed - 1, rest - 1);
        return Math.max(l, r);
    }

}
